package com.kjlink.widget.monitoring.config;

import com.kjlink.common.base.tool.Tools;
import com.kjlink.widget.monitoring.aspect.MonitorEventReportAspect;
import com.kjlink.widget.monitoring.processor.MonitorEventSender;
import com.kjlink.widget.monitoring.report.MonitorEventReportFacade;
import com.kjlink.widget.monitoring.report.handler.BaseMonitorDataBuildHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 描述:
 *  测试发送用
 * @author Vic.xu
 * @since 2025-08-04 15:38
 */
@Slf4j
@Configuration
public class MonitorEventConfig {

    @Autowired(required = false)
    private List<BaseMonitorDataBuildHandler> buildHandlers;

    @Bean
    public MonitorEventSender monitorEventSender(StringRedisTemplate stringRedisTemplate) {
        log.info("init MonitorEventSender");
        return new MonitorEventSender(stringRedisTemplate);
    }


    @Bean
    public MonitorEventReportFacade monitorEventReportFacade(MonitorEventSender monitorEventSender) {
        log.info("init MonitorEventReportFacade");
        MonitorEventReportFacade monitorEventReportFacade = new MonitorEventReportFacade(monitorEventSender);
        monitorEventReportFacade.setBuildHandlers(buildHandlers);
        monitorEventReportFacade.setCommonFill(model -> {
            model.setOccurTime(LocalDateTime.now());
            model.setOccurPlace("test  aspect");
            model.setCreatedBy("test Vic.xu");
            if (model.getBusinessId() == null) {
                model.setBusinessId(Tools.randomUuid());
            }

        });
        return monitorEventReportFacade;
    }

    @Bean
    public MonitorEventReportAspect monitorEventReportAspect(MonitorEventReportFacade monitorEventReportFacade) {
        log.info("init MonitorEventReportAspect");
        return new MonitorEventReportAspect(monitorEventReportFacade);
    }
}
